package com.iamteer.day10;

import java.io.IOException;
import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class Config
 */
@WebServlet("/Config")
public class Config extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Config() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//获取 Servlet 名称
		String servletName = this.getServletConfig().getServletName();
		System.out.println(servletName);
		
		//获取 Servlet 的初始参数
		String path = this.getServletConfig().getInitParameter("path");
		System.out.println(path);
		
		//获取 Servlet 所有初始参数
		Enumeration<String> initParameterNames = this.getServletConfig().getInitParameterNames();
		while (initParameterNames.hasMoreElements()) {
			String initParameterName = (String) initParameterNames.nextElement();
			String initParameterValue = this.getServletConfig().getInitParameter(initParameterName);
			System.out.println(initParameterName + "=" + initParameterValue);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
